package com.zh.test.service;

import com.zh.test.MapAndList.Array;
import org.assertj.core.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
//@Service
public class testServiceImpl {
    @Autowired
    JdbcTemplate jdbcTemplate;
    public void test1(){
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select *  from bi_record_change");
        maps.stream().forEach(m->{m.forEach((k,v)->{System.out.println(k+":"+v);});});
    }
    public List test2(){
        //todo 静态替换 ?  动态拼接
        HashMap<String,List> m = new HashMap();
        m.put("ids", Arrays.asList(new String[]{"2","3","4"}));

        MapSqlParameterSource parameters = new MapSqlParameterSource();
        parameters.addValue("ids",m);
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select *  from bi_record_change where id in(:ids)", parameters);
        return maps;
    }
    public Map test3(String id){
        String sql  = "select *  from bi_record_change where id = "+ id;
        Map map = jdbcTemplate.queryForObject(sql, Map.class);
        return map;
    }

}
